package ua.org.nuos.sdms.middle.util;

import org.apache.commons.lang.Validate;
import ua.org.nuos.sdms.middle.vo.CustomMessage;

import java.util.Arrays;

/**
 * Created by IntelliJ IDEA.
 * User: dio
 * Date: 06.11.11
 * Time: 13:44
 * To change this template use File | Settings | File Templates.
 */
public class MailMessageConstructor {

    public static final String CODE = "code";
    public static final String MAIL = "mail";

    public static CustomMessage createEmailVerificationMessage(String userMail, String basicUrl, String code) {
        Validate.notEmpty(userMail, "\"userMail\" can`t be empty");

        String link = createCompleteRegistrationLink(basicUrl, code);
        String content = createMessageContent(link);

        CustomMessage message = new CustomMessage();
        message.setContent(content);
        message.setFrom("SDMS");
        message.setSubject("Completing registration on SDMS");
        message.setRecipientList(Arrays.asList(new String[]{userMail}));
        return message;
    }

    protected static String createMessageContent(String link) {
        String content = "Для подтверждения email адреса требуется перейти по ссылке: %s";
        return String.format(content, link);
    }

    protected static String createCompleteRegistrationLink(String basicUrl, String code) {
        return String.format("%s?%s=%s",basicUrl, CODE, code);
    }

}
